import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
// https://vitejs.dev/config/
export default ({ mode }) =>
  defineConfig({
    plugins: [
      vue(),
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
    server: {
      proxy: {
        "/api": {
          target: "http://gmall-h5-api.atguigu.cn/",
          changeOrigin: true,
        },
      },
    },
    //环境变量
    define: {
      "process.env": loadEnv(mode, process.cwd()),
    },
    //路径别名
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"),
      },
    },
  });
